package com.yanqu.road.server.cmd.kuang;

import com.yanqu.road.entity.kuang.group.KuangMatchGroup;
import com.yanqu.road.logic.pb.CrossKuangPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.kuang.Kuang;
import com.yanqu.road.server.CrossBattleServer;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.manager.kuang.CrossKuangMgr;
import com.yanqu.road.server.protocol.CrossProtocol;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = CrossProtocol.C_CROSS_KUANG_MATCH_GROUP_SYNC, desc = "同步分组数据")
public class CrossMatchGroupSyncCmd extends CrossUnionCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        Kuang.CrossNotifyMatchGroupToActivityMsg syncMsg =Kuang.CrossNotifyMatchGroupToActivityMsg.parseFrom(packet.getBytes());
        if (syncMsg.getCrossId() != CrossBattleServer.getInstance().getServerId()) {
            return;
        }
        List<KuangMatchGroup> matchGroupList = new ArrayList<>();
        for (Kuang.KuangMatchGroupTemp groupTemp : syncMsg.getGroupList()) {
            matchGroupList.add(CrossKuangPb.parseKuangMatchGroup(groupTemp));
        }
        CrossKuangMgr.syncMatchGroup(matchGroupList);
    }

    @Override
    public void sendData() {
    }
}
